package com.ruoyi.interviews.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.resumes.domain.Resumes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.interviews.mapper.InterviewsMapper;
import com.ruoyi.interviews.domain.Interviews;
import com.ruoyi.interviews.service.IInterviewsService;

/**
 * 面试记录Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-10
 */
@Service
public class InterviewsServiceImpl implements IInterviewsService
{
    @Autowired
    private InterviewsMapper interviewsMapper;

    /**
     * 查询面试记录
     *
     * @param interviewId 面试记录主键
     * @return 面试记录
     */
    @Override
    public Interviews selectInterviewsByInterviewId(Long interviewId)
    {
        return interviewsMapper.selectInterviewsByInterviewId(interviewId);
    }

    /**
     * 查询面试记录列表
     *
     * @param interviews 面试记录
     * @return 面试记录
     */
    @Override
    public List<Interviews> selectInterviewsList(Interviews interviews)
    {
        //获取当前用户id
        Long userId= SecurityUtils.getUserId();
        //获取role_id
        List roleId=interviewsMapper.getRoleId(userId);
        //判断是否是应聘者
        if (roleId.contains(100)){
            List<Interviews> interviews1= interviewsMapper.selectInterviewsByUserId(userId);
            List<Interviews> interviews2=interviewsMapper.selectInterviewsList(interviews);
            //两个集合取交集
            Set<Interviews> set=new HashSet<>(interviews1);
            List<Interviews> list=new ArrayList<>();
            for(Interviews interview:interviews2){
                if(set.contains(interview)){
                    list.add(interview);
                }
            }
            return list;
        }else if(roleId.contains(103)) {  //判断是否是面试官
            List<Interviews> interviews1= interviewsMapper.selectInterviewsByRoleId(userId);
            List<Interviews> interviews2=interviewsMapper.selectInterviewsList(interviews);
            //两个集合取交集
            Set<Interviews> set=new HashSet<>(interviews1);
            List<Interviews> list=new ArrayList<>();
            for(Interviews interview:interviews2){
                if(set.contains(interview)){
                    list.add(interview);
                }
            }
            return list;
        }else if(roleId.contains(101)){ //公司账号
            List<Interviews> interviews1= interviewsMapper.selectInterviewsByCompany(userId);
            List<Interviews> interviews2=interviewsMapper.selectInterviewsList(interviews);
            //两个集合取交集---搜索功能生效
            Set<Interviews> set=new HashSet<>(interviews1);
            List<Interviews> list=new ArrayList<>();
            for(Interviews interview:interviews2){
                if(set.contains(interview)){
                    list.add(interview);
                }
            }
            return list;
        }
        return interviewsMapper.selectInterviewsList(interviews);
    }

    /**
     * 新增面试记录
     *
     * @param interviews 面试记录
     * @return 结果
     */
    @Override
    public int insertInterviews(Interviews interviews)
    {
        return interviewsMapper.insertInterviews(interviews);
    }

    /**
     * 修改面试记录
     *
     * @param interviews 面试记录
     * @return 结果
     */
    @Override
    public int updateInterviews(Interviews interviews)
    {
        return interviewsMapper.updateInterviews(interviews);
    }

    /**
     * 批量删除面试记录
     *
     * @param interviewIds 需要删除的面试记录主键
     * @return 结果
     */
    @Override
    public int deleteInterviewsByInterviewIds(Long[] interviewIds)
    {
        return interviewsMapper.deleteInterviewsByInterviewIds(interviewIds);
    }

    /**
     * 删除面试记录信息
     *
     * @param interviewId 面试记录主键
     * @return 结果
     */
    @Override
    public int deleteInterviewsByInterviewId(Long interviewId)
    {
        return interviewsMapper.deleteInterviewsByInterviewId(interviewId);
    }

    @Override
    public List<Interviews> selectday() {
        return interviewsMapper.selectday();
    }

    @Override
    public int deleteAll() {

        return interviewsMapper.deleteAll();
    }
}
